<?php

/*
 * site/authenticate_service.php
 *
 */

Service::register( 'AuthenticateService', 'Site authentification service', 'helpless' );

class AuthenticateService extends Service
{
	public function __construct()
	{
		parent::__construct();
		$this->registerMethod( 'getInfo', array(), 'Return current user informations', 'helpless', true );
		$this->registerMethod( 'authenticate', array(T_STR, T_STR), 'Authenticate user', 'helpless', true );
	}

	public function getInfo()
	{
		$r = array();
		$r['isAuthenticate'] = Auth::isAuthenticate();
		$r['username'] = Auth::getUsername();
		$r['UILabelManagable'] = Auth::isCallAllowed( 'LabelService', 'add' ) &&
														 Auth::isCallAllowed( 'LabelService', 'remove' ) &&
														 Auth::isCallAllowed( 'LabelService', 'update' );
		$r['UILinkAddable'] = Auth::isCallAllowed( 'LinkService', 'add' );
		$r['UILinkEditable'] = Auth::isCallAllowed( 'LinkService', 'update' );
		$r['UILinkRemovable'] = Auth::isCallAllowed( 'LinkService', 'remove' );
		$r['UIHomeEditable'] = Auth::isCallAllowed( 'HomeService', 'setText' );
		return $r;
	}

	public function authenticate( $user, $password )
	{
		Auth::authenticate( $user, $password );

		return AuthenticateService::getInfo();
	}

};

?>
